package com.dlb.andorid.presenter;

import com.dlb.andorid.App;
import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.AddressRetrieval;
import com.dlb.andorid.bean.ArgAddAddress;
import com.dlb.andorid.bean.ArgAddAddressDate;
import com.dlb.andorid.bean.MyAddress;
import com.dlb.andorid.bean.Province;

import java.util.HashMap;
import java.util.List;

public class AddressPresenter extends XPresenter {


	XContract.IAddressView iView;

	public AddressPresenter(XContract.IAddressView iView) {
		super(iView);
		this.iView = iView;

	}


	public void getCity() {
		mModel.getAddressCity();
	}

	public void addAddress(String name, int sex,String phone, long province, long city, long area, String areaInfo,String latitude,String longitude) {

		ArgAddAddress arg = new ArgAddAddress();
		arg.setUser_id(App.mUserInfo.getUid());
		ArgAddAddressDate date = new ArgAddAddressDate();
		date.setArea(area);
		date.setAreainfo(areaInfo);
		date.setCity(city);
		date.setPhone(phone);
		date.setSex(sex);
		date.setName(name);
		date.setMerchant_id(1);
		date.setProvince(province);
		date.setLatitude(latitude);
		date.setLongitude(longitude);
		arg.setData(date);

		mModel.addAddress(arg);
	}

	public void editAddress(long address_id,String name, int sex,String phone, long province, long city, long area, String areaInfo,String latitude,String longitude) {

		ArgAddAddress arg = new ArgAddAddress();
		arg.setUser_id(App.mUserInfo.getUid());
		arg.setAddress_id(address_id);
		ArgAddAddressDate date = new ArgAddAddressDate();
		date.setArea(area);
		date.setAreainfo(areaInfo);
		date.setCity(city);
		date.setPhone(phone);
		date.setSex(sex);
		date.setName(name);
		date.setMerchant_id(1);
		date.setProvince(province);
		date.setLatitude(latitude);
		date.setLongitude(longitude);
		arg.setData(date);

		mModel.editAddress(arg);
	}

	public void getAddressList() {
		mModel.getAddress();
	}

	public void getAddressRetrieval(long province_id, long city_id, long area_id, String keyword){
		mModel.getAddressRetrieval(province_id,city_id,area_id,keyword);
	}

	public void deleteAddress(long address_id){
		mModel.deleteAddress(address_id);
	}

	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);
		switch (vocational_id) {
			case XAPI.GET_ADDRESS_CITYS_VOCATIONAL_ID:
				iView.getAddressCitySuccess(((XServerMsg<List<Province>>) data).getData());
				break;
			case XAPI.ADD_ADDRESS_VOCATIONAL_ID:
				iView.addAddressSuccess(((XServerMsg) data).getMsg());
				break;
			case XAPI.GET_ADDRESS_VOCATIONAL_ID:
				iView.getAddressSuccess(((XServerMsg<List<MyAddress>>) data).getData());
				break;
			case XAPI.GET_ADDRESS_RETRIEVAL_VOCATIONAL_ID:
				iView.getAddressRetrievalSuccess(((XServerMsg<List<AddressRetrieval>>) data).getData()  );
				break;
			case XAPI.DELETE_ADDRESS:
				iView.deleteAddSuccess((XServerMsg) data);
				break;
			case XAPI.EDIT_ADDRESS_VOCATIONAL_ID:
				iView.addAddressSuccess(((XServerMsg) data).getMsg());
				break;
		}
	}
}
